package services

import (
	"github.com/labstack/gommon/log"
	"law_case_api/models"
)

// CreateContractEvent 创建客户合同事项记录
func (contract ContractService) CreateContractEvent(wzjContractEvent models.WzjContractEvent) (bool, error) {
	if err := db.Create(&wzjContractEvent).Error; err != nil {
		log.Error("CreateContractEvent--创建客户合同事项记录失败,失败原因：", err)
		return false, err
	}
	return true, nil
}

// GetContractEventListByContractId 根据登录人信息获取事项记录列表
func (contract ContractService) GetContractEventListByContractId(contractId, pageIndex, pageSize int) ([]models.WzjContractEvent, int64, error) {
	var wzjContractEvents []models.WzjContractEvent
	dataCount := int64(0)
	if err := db.Count(&dataCount).
		Where("contract_id=?", contractId).
		Select("event_id,contract_id,event_content,create_user_id,create_date").
		Order("create_date desc").
		Find(&wzjContractEvents).Error; err != nil {
		log.Error("GetContractEventListByContractId--查询失败,失败原因：", err)
		return wzjContractEvents, dataCount, err
	}
	return wzjContractEvents, dataCount, nil
}
